package tech.veedo.munchkin.controllers.backend;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import tech.veedo.munchkin.beans.backend.Node;
import tech.veedo.munchkin.constants.Operation;
import tech.veedo.munchkin.services.backend.NodeService;
import tech.veedo.munchkin.verifications.backend.NodeVerify;

import java.util.List;

/**
 * Node 示例类
 */
@RestController
@RequestMapping("/munc/node")
@Api(tags = "1-后台-3-审核节点接口结合")
public class NodeController {

    private final NodeService nodeService;

    private final NodeVerify nodeVerify;

    public NodeController(NodeService nodeService, NodeVerify nodeVerify) {
        this.nodeService = nodeService;
        this.nodeVerify = nodeVerify;
    }

    @ApiOperation("添加审核节点")
    @PostMapping("/save")
    public boolean save(Node node) {
        nodeVerify.verify(Operation.ADD, node);
        return nodeService.saveNode(node);
    }

    @ApiOperation("更新审核节点")
    @PostMapping("/update")
    public boolean update(Node node) {
        nodeVerify.verify(Operation.UPDATE, node);
        return nodeService.updateNode(node);
    }

    @ApiOperation("删除审核节点")
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return nodeService.deleteNode(id);
    }

    @ApiOperation("根据mappingId查询审批流下节点链")
    @GetMapping("/{mappingid}")
    public List<Node> chain(@PathVariable Long mappingid) {
        return nodeService.chain(mappingid);
    }

}
